//
//  HHCollectionViewController.m
//  Flower
//
//  Created by 花花 on 2016/12/6.
//  Copyright © 2016年 花花. All rights reserved.
//

#import "HHCollectionViewController.h"
#import "HHTest2ViewController.h"
@interface HHCollectionViewController ()<UICollectionViewDelegate, UICollectionViewDataSource>
@property(nonatomic, weak) UICollectionView *collectView;
@end

static NSString *const cellID = @"cellID";
@implementation HHCollectionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self setupCollectionView];
}

#pragma mark - Setter && Getter
-(void )setupCollectionView{

    
        UICollectionViewFlowLayout *layout =[[UICollectionViewFlowLayout alloc]init];
    
        
        UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, screen_width, screen_height-45) collectionViewLayout:layout];
    collectionView.backgroundColor =[UIColor greenColor];
        collectionView.delegate = self;
        collectionView.dataSource = self;
        // 这个设置上面的内容偏移量为ZJVc9Controller里面定义的常量defaultOffSetY
    
        [collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:cellID];
        [self.view addSubview:collectionView];
        _collectView =  collectionView;
  

}
#pragma mark - <UICollectionViewDelegate, UICollectionViewDataSource>
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 50;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
    cell.backgroundColor = [UIColor orangeColor];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    HHTest2ViewController *vc = [[HHTest2ViewController alloc]init];
    [self.navigationController showViewController:vc sender:nil];
}


-(void)scrollViewDidScroll:(UIScrollView *)scrollView{

    [self.delegate scrollViewIsScrolling:scrollView];

}

// 重写父类的方法, 返回这个控制器的scrollView
-(UIScrollView *)scrollView{

    return self.collectView;
    

}
//每个item的尺寸
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    CGFloat cellWidth = (screen_width-4)/4;
    
    return CGSizeMake(cellWidth, 80);

    

}
//设置每个item的水平间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    
    
    return 1;
}

//设置每个item垂直间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    
    return 2;
}
//设置每个item的UIEdgeInsets
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    
    return UIEdgeInsetsMake(0, 0, 0, 0);
    
}

@end
